<?php
//include_once '../utility/arrayutil.php';
class Province {

    private $id;
    private $name;

    public function __construct($_id, $_name) {
        $this->id = $_id;
        $this->name = $_name;
    }

    public function setId($_id) {
        $this->id = $_id;
    }

    public function getId() {
        return $this->id;
    }

    public function setName($_name) {
        $this->name = $_name;
    }

    public function getName() {
        return $this->name;
    }

    public function save() {
        mysql_query("insert into province(name) values('$this->name')");
    }

    public static function delete($_id) {
        mysql_query("delete from province where id=$_id");
    }

    public function update() {
        mysql_query("update province set name='$this->name' where id=$this->id");
    }

    public static function load($_id) {
        $result = mysql_query("select id,name from province where id=$_id");
        $row = mysql_fetch_row($result);
        $province = new Province($row[0], $row[1]);
        return $province;
    }

    public static function loads() {
        $result = mysql_query("select id,name from province");
        $provinces = array();
        while ($row = mysql_fetch_array($result)) {
            $prov = new Province($row['id'], $row['name']);
            array_push($provinces, $prov);
        }
        return $provinces;
    }
    
    public static function loadJSON($_id){ 
        return json_encode(objectArray(Province::load($_id)));
    }
    
    public static function loadsJSON(){
        return json_encode(arrayOfObjectToArray(Province::loads()));
    }
    

}

?>
